<template>
	<view class="evaluate">
		<view class="detailBox">
			<image :src="pageData.products_image" style="width: 160rpx;height: 160rpx;border-radius: 10rpx;" mode="">
			</image>
			<view class="message">
				<view class="name">
					{{pageData.products_name}}
				</view>
				<view class="desc">
					规格：{{pageData.sku_text}}
				</view>
				<view class="bottom">
					<view class="price">
						₱{{pageData.price}}
					</view>
					<view class="number">
						x{{pageData.num}}
					</view>
				</view>
			</view>
		</view>

		<view class="evalueBox">
			<view class="evalueMessage">
				<view class="messageItem">
					<view class="lable">
						商品质量
					</view>
					<view class="">
						<u-rate :count="count" v-model="value1" activeColor="#FFA42F"></u-rate>
					</view>
				</view>
				<!-- 	<view class="messageItem">
					<view class="lable">
						服务态度
					</view>
					<view class="">
						<u-rate :count="count" v-model="value2" activeColor="#FFA42F"></u-rate>
					</view>
				</view>
				<view class="messageItem">
					<view class="lable">
						物流服务
					</view>
					<view class="">
						<u-rate :count="count" v-model="value3" activeColor="#FFA42F"></u-rate>
					</view>
				</view> -->

			</view>

			<view class="evaluateContent">
				<textarea class="content" v-model="content" name="" id=""
					placeholder="商品满足你的期待么？说说你的想法，分享给想买的他们ba~"></textarea>
				<view class="MT_30" style="display: flex;">
					<view class="" v-for="(item,index) in portrait" :key="index" style="position: relative;">
						<image :src="item" mode="aspectFit"
							style="width: 160rpx;height: 160rpx;margin-right: 20rpx;display: flex;margin-right: 30rpx;">
						</image>
						<view class="" style="position: absolute;top: 10rpx; left: 155rpx;color: red;width: 100rpx;"
							@click="shanchuImg(index,1)"><u-icon name="close" color="red"></u-icon>
						</view>
					</view>

					<image v-if="portrait.length==3?false:true" src="../../static/image/upload.png"
						style="width: 160rpx;height: 160rpx;" mode="" @click="modufyimage"></image>
				</view>
			</view>

		</view>


		<view class="evaluateBtn" @click="handleSave">
			立即评价
		</view>

	</view>
</template>

<script>
	import {
		commentorder,
		uploadImg
	} from "@/api/api.js"
	export default {
		data() {
			return {
				count: 5,
				value1: 0,
				value2: 0,
				value3: 0,
				pageData: {},
				portrait: [],
				content: "",
			}
		},
		onLoad(optiond) {
			this.pageData = JSON.parse(optiond.data)
			console.log("options", this.pageData)

		},
		methods: {

			// 获取用户相册
			modufyimage(e) {
				const that = this
				uni.chooseImage({
					count: 3, // 最多可以选择的图片张数，默认9/这里可以限制照片数量
					sizeType: ['original', 'compressed'], //original 原图，compressed 压缩图，默认二者都有
					sourceType: ['album', 'camera'], //album 从相册选图，camera 使用相机，默认二者都有。如需直接开相机或直接选相册，请只使用一个选项
					success: function(res) {
						uni.showToast({
							title: '上传中..',
							icon: "loading",
							duration: 2000
						});
						console.log(res)
						for (let i = 0; i < res.tempFilePaths.length; i++) {
							// const len = that.imageList.length
							uni.uploadFile({
								url: uploadImg, //仅为示例，非真实的接口地址
								filePath: res.tempFilePaths[i],
								name: 'file', //这里注意修改成后端需要的字段
								formData: {},
								// header: {
								// 	"Content-Type": "application/form-data",
								// 	"Authorization": 'Bearer' + ' ' + that.token
								// },
								success: (uploadFileRes) => {
									let a = JSON.parse(uploadFileRes.data)
									that.portrait.push(a.data)
									uni.showToast({
										title: '上传成功！',
										icon: "none",
										duration: 1000
									});
								},
								fail: (e) => {
									console.log("网络请求fail");
								},
							});
						}
					}
				})
			},

			// 删除图片
			shanchuImg(e, i) {
				if (i == 1) {
					this.portrait.splice(e, 1);
				}
			},

			async handleSave() {
				if (this.value1 == 0) {
					uni.showToast({
						title: '请先对商品质量进行评分！',
						icon: "none",
						duration: 2000
					});
					return
				}
				let data = {
					content: this.content,
					images: this.portrait.join(','),
					id: this.pageData.id,
					stars: this.value1,
				}
				let res = await commentorder(data)
				if (res.code == 1000) {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 2000
					});
					setTimeout(() => {
						uni.navigateBack({
							delta: 1
						})
					}, 2000)

				} else {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 2000
					});
				}
				console.log("data", data)
			},
		}
	}
</script>

<style scoped lang="scss">
	.evaluate {
		.evaluateBtn {
			width: 670rpx;
			height: 80rpx;
			background: #439B05;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 80rpx;
			text-align: center;
			border-radius: 80rpx;
			position: absolute;
			bottom: 100rpx;
			left: 40rpx;
		}

		.detailBox {
			display: flex;
			margin-top: 1rpx;
			width: 100%;
			padding: 30rpx;
			box-sizing: border-box;
			background-color: #ffffff;

			.message {
				margin-left: 20rpx;

				.name {
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					color: #333333;
					line-height: 30rpx;
					width: 450rpx;
				}

				.desc {
					font-size: 24rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #999999;
					line-height: 28rpx;
					margin-top: 20rpx;
				}

				.bottom {
					display: flex;
					width: 100%;
					justify-content: space-between;
					margin-top: 34rpx;

					.price {
						font-size: 32rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #333333;
						line-height: 38rpx;
					}

					.number {
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #999999;
						line-height: 33rpx;
					}
				}
			}
		}

		.evalueBox {
			width: 750rpx;
			background: #FFFFFF;
			margin-top: 2rpx;
			padding: 30rpx;
			box-sizing: border-box;

			.evalueMessage {
				.messageItem {
					display: flex;
					margin-bottom: 20rpx;

					.lable {
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #333333;
						line-height: 33rpx;
						margin-right: 20rpx;
					}
				}

			}

			.evaluateContent {
				width: 690rpx;
				// height: 300rpx;
				background: #F5F5F5;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				padding: 30rpx;
				box-sizing: border-box;

				.content {
					width: 650rpx;
					height: 120rpx;
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #999999;
					line-height: 33rpx;
					margin-bottom: 20rpx;
				}
			}
		}

	}
</style>